package com.cloudkinto.utils;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import tiktokshop.open.sdk_java.invoke.ApiClient;
import tiktokshop.open.sdk_java.invoke.ApiException;
import tiktokshop.open.sdk_java.invoke.JSON;


public class CustomApiClient extends ApiClient {
    public CustomApiClient() {
        super();
    }
    //重写serialize方法
    @Override
    public RequestBody serialize(Object obj, String contentType) throws ApiException {
     if (isJsonMime(contentType)) {
            String content;
            if (obj != null) {
                content = JSON.serialize(obj);
            } else {
                content = null;
            }
            return RequestBody.create(MediaType.parse(contentType), content);
        } else if (obj instanceof String) {
            return RequestBody.create(MediaType.parse(contentType), (String) obj);
        } else {
            throw new ApiException("Content type \"" + contentType + "\" is not supported");
        }
    }
}